package com.lino.design;

import com.alibaba.fastjson.JSON;

import java.util.Map;

/**
 * @description: MQ消息统一适配类
 * @author: lingjian
 * @createDate: 2022/12/20 10:49
 */
public class MQAdapter {

    /**
     * 映射属性
     *
     * @param strJson 字段名称
     * @param link    属性集合
     * @return RebateInfo
     * @throws Exception
     */
    public static RebateInfo filter(String strJson, Map<String, String> link) throws Exception {
        return filter(JSON.parseObject(strJson, Map.class), link);
    }

    /**
     * 映射属性
     *
     * @param obj  集合
     * @param link 属性集合
     * @return RebateInfo
     * @throws Exception
     */
    public static RebateInfo filter(Map obj, Map<String, String> link) throws Exception {
        RebateInfo rebateInfo = new RebateInfo();
        for (String key : link.keySet()) {
            Object val = obj.get(link.get(key));
            RebateInfo.class.getMethod("set" + key.substring(0, 1).toUpperCase() + key.substring(1), String.class).invoke(rebateInfo, val.toString());
        }
        return rebateInfo;
    }

}
